package com.dp.mallchat.common.common.event.listener;

import com.dp.mallchat.common.common.event.FriendEvent;
import com.dp.mallchat.common.user.dao.UserApplyDao;
import com.dp.mallchat.common.user.domain.entity.UserApply;
import com.dp.mallchat.common.user.domain.ws.resp.WSFriendApply;
import com.dp.mallchat.common.user.service.adapter.WSAdapter;
import com.dp.mallchat.common.user.service.impl.PushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: dupeng
 * @CreateTime: 2024-06-24  18:49
 * @Description: 好有事件监听
 */
@Component
public class FriendEventListener {

    @Autowired
    private PushService pushService;
    @Autowired
    private UserApplyDao userApplyDao;
    /**
     * 好有申请事件
     * @param event
     */
    @Async
    @EventListener(classes = FriendEvent.class)
    public void userApply(FriendEvent event){
        //对方好友申请未读小红标
        UserApply userApply = event.getUserApply();
        Integer unReadCount = userApplyDao.getUnReadCount(userApply.getTargetId());
        pushService.sendPushMsg(WSAdapter.buildApplySend(new WSFriendApply(userApply.getUid(), unReadCount)), userApply.getTargetId());
    }


}
